package cn.goodym.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.goodym.mapper.EnvMapper;
import cn.goodym.po.Env;
import cn.goodym.po.PagingVO;
import cn.goodym.service.EnvService;

@Service("envService")
public class EnvServiceImpl implements EnvService {

	@Autowired
	private EnvMapper envMapper;

	public int getCount() {
		return envMapper.countByExample();
	}

	public List<Env> findByPaging(Integer toPageNo) {
		PagingVO pagingVO = new PagingVO();
		pagingVO.setToPageNo(toPageNo);
		List<Env> list = envMapper.findByPaging(pagingVO);

		return list;
	}

	public Boolean save(Env env) {
		Env envs = envMapper.selectByPrimaryKey(env.getId());
		if (envs == null) {
			envMapper.insert(env);
			return true;
		}
		return false;
	}

	@Override
	public void removeById(Integer id) {
		envMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Env findById(Integer id) {
		return envMapper.selectByPrimaryKey(id);
	}

	@Override
	public void updateById(Integer id, Env env) {
		envMapper.updateByPrimaryKey(env);
	}

	@Override
	public List<Env> findByName(String name) {
		List<Env> list = envMapper.selectByExample(name);
		return list;
	}

	@Override
	public List<Env> findAll() {
		return envMapper.findAll();
	}

}
